package com.arlen.general.util;

import com.arlen.general.exceptionHandle.WxCustomException;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@Component
public class ErrorMesUtils {
    public void captureExcept(HttpServletResponse response, HttpServletRequest request ,String message) {
        response.setContentType("application/json;charset=utf-8");
        Map<String, String> mesMap = MessageThread.getMessageThread();
        String requestMes = "<xml>\n" +
                "  <ToUserName><![CDATA[" + mesMap.get("FromUserName") + "]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[" + mesMap.get("ToUserName") + "]]></FromUserName>\n" +
                "  <CreateTime>" + System.currentTimeMillis() / 1000 + "</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA[" + message + "]]></Content>\n" +
                "</xml>";
        try (PrintWriter writer = response.getWriter();) {
            writer.write(requestMes);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
